package cn.change360.newappchildrenenglish;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

import com.activeandroid.query.Select;

import java.util.List;

import cn.change360.newappchildrenenglish.adapter.ColumnsAdapter;
import cn.change360.newappchildrenenglish.mode.Columns;


/*
* 常用句
* */

public class CharactersActivity extends AppCompatActivity implements View.OnClickListener {

    ImageButton topbar_back;
    TextView topbar_title;

    ListView listView;
    List<Columns> columnList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_characters);

        initView();
    }

    private void initView() {
        topbar_back = (ImageButton) findViewById(R.id.topbar_back);
        topbar_title = (TextView) findViewById(R.id.topbar_title);
        topbar_title.setText("常用句");
        topbar_back.setOnClickListener(this);

        listView = (ListView) findViewById(R.id.listView);
        columnList = new Select().from(Columns.class).where("column_column_id=45").orderBy("column_sort asc").execute();
        listView.setAdapter(new ColumnsAdapter(this, columnList));

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent(CharactersActivity.this, CharactersShowActivity.class);
                intent.putExtra("columns_id", columnList.get(i).getId());
                startActivity(intent);
            }
        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.topbar_back:
                finish();
                break;
        }
    }
}
